package cn.edu.zxj.product.service.controller;

import cn.edu.zxj.product.service.service.ProductService;
import cn.edu.zxj.productapi.api.ProductInterface;
import cn.edu.zxj.productapi.model.ProductInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description：
 *
 * @author: zxj
 * @date: 2024-09-28
 * @time: 12:44:36
 */
@RestController
@RequestMapping("/product")
@Slf4j
public class ProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping("/test")
    public String list() {
        return "product test";
    }


    @RequestMapping("/{productId}")
    public ProductInfo getProductInfo(@PathVariable("productId") Integer productId) {
        log.info("接收到请求, productId:{}", productId);
        return productService.getProductInfo(productId);
    }


    /*
     * feign 参数传递: 单个参数
     */
    @RequestMapping("/p1")
    public String getProductInfoByFeign(Integer id) {
        log.info("接收到请求, id:{}", id);
        return "id:" + id;
    }

    /*
     * feign 参数传递: 多个参数
     */
    @RequestMapping("/p2")
    public String getProductInfoByFeign(Integer id, String name) {
        log.info("接收到请求, id:{}, p2:{}", id, name);
        return "id:" + id + ", p2:" + name;

    }



    /*
     * feign 参数传递: 对象
     */
    @RequestMapping("/p3")
    public String getProductInfoByFeign(ProductInfo productInfo) {
        log.info("接收到请求, productInfo:{}", productInfo);
        return "productInfo:" + productInfo;
    }

    @RequestMapping("/p4")
    public String p3(ProductInfo productInfo) {
        log.info("接收到请求, productInfo:{}", productInfo);
        return "product 接收到对象, productInfo:" + productInfo;
    }

    @RequestMapping("/p5")
    public String p4(@RequestBody ProductInfo productInfo) {
        log.info("接收到请求, productInfo:{}", productInfo);
        return "product 接收到对象, productInfo:" + productInfo;
    }
}
